﻿Imports System
Imports System.IO
Imports System.Data.OleDb
Imports System.Data
Imports System.Drawing
Imports System.Drawing.Imaging
Namespace Arwani
    Partial Class Backend_AddEditContactList
        Inherits System.Web.UI.Page

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            If (Session("ADMIN_USER") IsNot Nothing) Then
                If Page.IsPostBack Then Exit Sub
                If Request.QueryString("id") <> "0" Then
                    Call getPromoById(Request.QueryString("id").ToString())
                End If
            Else
                Response.Redirect("Default.aspx")
            End If

        End Sub

        Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
            Dim strQ As String
            Dim arwCon As New ArwaniController
            strQ = "update Contact set Name='" & txtName.Text & "', Phone='" & txtPhone.Text & "', Email='" & txtEmail.Text & "',Message='" & txtMessage.Text & "' where id=" & Val(Request.QueryString("id"))
            arwCon.ExecuteNonQuery(strQ)
            Response.Redirect("ContactList.aspx")


        End Sub


        Public Sub getPromoById(ByVal Id As String)
            Dim arwCon As New ArwaniController
            Dim strQ As String = "select * from Contact where id=" & Id
            Dim dtTable As DataTable = arwCon.ExecuteQuery(strQ)
            If dtTable.Rows.Count > 0 Then
                If Not IsDBNull(dtTable.Rows(0)("Name")) Then Me.txtName.Text = dtTable.Rows(0)("Name")
                If Not IsDBNull(dtTable.Rows(0)("Phone")) Then Me.txtPhone.Text = dtTable.Rows(0)("Phone")
                If Not IsDBNull(dtTable.Rows(0)("Email")) Then Me.txtEmail.Text = dtTable.Rows(0)("Email")
                If Not IsDBNull(dtTable.Rows(0)("Message")) Then Me.txtMessage.Text = dtTable.Rows(0)("Message")


            End If
        End Sub

        Protected Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click
            Response.Redirect("ContactList.aspx")
        End Sub
    End Class
End Namespace